package com.hzit.portal.controller;

import com.hzit.portal.service.PortalService;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.api.domain.Content;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@Controller
@RequestMapping
public class PortalController {

	@Autowired
	private PortalService portalService;
	//1. 门户首页
	@GetMapping({"/","/index.html"})
	public String index(Model model){
		//1.1 根据广告分类id找到对应的广告列表(首先查询出轮播图广告)
		// List<Content> contentList = portalService.findContentsByCateId(1L);
		// 1.2 解决了数据一致性问题(手动解决,代码与redis的耦合度太高)
		List<Content> contentList = portalService.findContentsByCateId2(1L);
		//  List<Content> contentList = portalService.findContentsByCateId3(1L);

		// 1.2 将广告列表放到model中存放在thymeleaf中显示
		model.addAttribute("contentList",contentList);
		return "index";  // 转换为物理视图----》  classpath: /templates/index.html
	}

	@GetMapping("/{id}")
	@ResponseBody
	public AjaxResult findById(@PathVariable Long id){
		Content content = portalService.findById(id);
		return AjaxResult.success(content);
	}
}
